package gold.digger;

import gold.utils.InputUtil;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2100 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public List<Integer> goodDaysToRobBank(int[] security, int time) {
            int n = security.length;
            List<Integer> ans = new ArrayList<>();
            if (time == 0) {
                for (int i = 0; i < n; i++) {
                    ans.add(i);
                }
                return ans;
            }
            if (2 * time >= security.length) return new ArrayList<>();
            int[] pre = new int[n], after = new int[n];

            for (int i = 1; i < n; i++) {
                if (security[i] <= security[i - 1]) pre[i] = pre[i - 1] + 1;
            }
            for (int i = n - 2; i >= 0; i--) {
                if (security[i] <= security[i + 1]) after[i] = after[i + 1] + 1;
            }

            for (int i = 1; i < n; i++) {
                if (pre[i] >= time && after[i] >= time) ans.add(i);
            }

            return ans;
        }
    }

    public void run() {
//        System.out.println(new Solution().goodDaysToRobBank(InputUtil.toIntegerArray("[5,3,3,3,5,6,2]"), 2));
//        System.out.println(new Solution().goodDaysToRobBank(InputUtil.toIntegerArray("[1,1,1,1,1]"), 0));
//        System.out.println(new Solution().goodDaysToRobBank(InputUtil.toIntegerArray("[1,2,3,4,5,6]"), 2));
        System.out.println(new Solution().goodDaysToRobBank(InputUtil.toIntegerArray("[5,3,3,3,5,6,2]"), 2));
    }

    public static void main(String[] args) throws Exception {
        LC2100 an = new LC2100();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
